﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using NHibernate.Criterion;
using ZDSoft.TES.Entity;
using ZDSoft.TES.Service;
using ZDSoft.TES.Manager;

namespace ZDSoft.TES.Component
{
    public class ComponentBase<T, U> : IServiceBase<T>
        where T : EntityBase<T>, new()
        where U : ManagerBase<T>, new()
    {
        /// <summary>
        /// 用反射实例化U
        /// </summary>
        U u = (U)typeof(U).GetConstructor(Type.EmptyTypes).Invoke(null);

        public void Create(T t)
        {
            u.Create(t);
        }

        public void Update(T t)
        {
            u.Update(t);
        }

        public void Delete(int id)
        {
            u.Delete(id);
        }

        public T FindByID(int id)
        {
            return u.FindByID(id);
        }

        public IList<T> FindAll()
        {
            return u.FindAll();
        }

        public IList<T> Find(IList<ICriterion> queryConditions)
        {
            return u.Find(queryConditions);
        }

        public IList<T> GetPaged(IList<ICriterion> queryConditions, IList<Order> orderList, int pageIndex, int pageSize, out int count)
        {
            return u.GetPaged(queryConditions, orderList, pageIndex, pageSize, out count);
        }
    }
}
